Skip to content

从文件加载XML - XmlParseFile

函数简介

从文件加载并解析XML文档。

接口名称

XmlParseFile

DLL调用

c
int64_t XmlParseFile(const char* filepath, int32_t* err);

参数说明

参数名类型说明
filepath字符串XML文件路径。
err整数型错误码输出参数,可为NULL。

示例

SDK 调用

cpp
#include "OLAPlugServer.h"

OLAPlugServer ola;
// 从磁盘加载 XML 配置文件
int32_t err = 0;
int64_t doc = ola.XmlParseFile("config/app.xml", &err);
if (doc != 0 && err == 0) {
    int32_t rootErr = 0;
    int64_t root = ola.XmlGetRootElement(doc, &rootErr);
    ola.XmlFree(doc);
}
csharp
using OLAPlug;

var ola = new OLAPlugServer();
// 从磁盘加载 XML 配置文件
int err;
long doc = ola.XmlParseFile("config/app.xml", out err);
if (doc != 0 && err == 0)
{
    int rootErr;
    long root = ola.XmlGetRootElement(doc, out rootErr);
    ola.XmlFree(doc);
}
python
from OLAPlugServer import OLAPlugServer

ola = OLAPlugServer()
# 从磁盘加载 XML 配置文件
doc, err = ola.XmlParseFile("config/app.xml")
if doc != 0 and err == 0:
    root, root_err = ola.XmlGetRootElement(doc)
    ola.XmlFree(doc)
java
import com.olaplug.OLAPlugServer;
import com.sun.jna.ptr.IntByReference;

OLAPlugServer ola = new OLAPlugServer();
// 从磁盘加载 XML 配置文件
IntByReference err = new IntByReference(0);
long doc = com.olaplug.OLAPlugDLLHelper.XmlParseFile("config/app.xml", err);
if (doc != 0 && err.getValue() == 0) {
    ola.XmlFree(doc);
}
cpp
var ola = com("OlaPlug.OlaSoft")
var err = 0
var doc = ola.XmlParseFile("config/app.xml", err)
if(doc && err == 0) {
    ola.XmlFree(doc)
}
vbscript
Set ola = CreateObject("OlaPlug.OlaSoft")
err = 0
doc = ola.XmlParseFile("config/app.xml", err)
If doc <> 0 And err = 0 Then
    ola.XmlFree(doc)
End If
text
.局部变量 ola, OLAPlug
ola.创建 ()
err = 0
doc = ola.XmlParseFile ("config/app.xml", err)
.如果真 (doc ≠ 0 且 err = 0)
    ola.XmlFree (doc)
.如果真结束
aardio
import OLAPlugServer;
var ola = OLAPlugServer();
var err = 0;
var doc = ola.XmlParseFile("config/app.xml", err);
if(doc && !err){ ola.XmlFree(doc); }
text
变量 ola <类型 = OLAPlugServer>
ola = 新建 OLAPlugServer
整数 err = 0
长整数 doc = ola.XmlParseFile("config/app.xml", err)
如果真 (doc ≠ 0 且 err = 0)
{
    ola.XmlFree(doc)
}
cpp
#include "OLAPlugServer.h"

OLAPlugServer ola;
int32_t err = 0;
int64_t doc = ola.XmlParseFile("config/app.xml", &err);
if (doc != 0 && err == 0) {
    ola.XmlFree(doc);
}

原生 DLL 调用

cpp
long instance = CreateCOLAPlugInterFace();
int err = 0;
long doc = XmlParseFile(instance, "config/app.xml", &err);
if (doc != 0) {
    XmlFree(instance, doc);
}
csharp
using System.Runtime.InteropServices;
using System.Text;

[DllImport("OLAPlug_x64.dll", CallingConvention = CallingConvention.StdCall)]
static extern long CreateCOLAPlugInterFace();

long instance = CreateCOLAPlugInterFace();
int err = 0;
long doc = XmlParseFile(instance, "config/app.xml", err);
if (doc != 0) XmlFree(instance, doc);
python
from ctypes import CDLL, c_int, c_int64, create_string_buffer

ola = CDLL("OLAPlug_x64.dll")
ola.CreateCOLAPlugInterFace.restype = c_int64
instance = ola.CreateCOLAPlugInterFace()
err = c_int(0)
doc = ola.XmlParseFile(instance, b"config/app.xml", err)
if doc:
    ola.XmlFree(instance, doc)

返回值

返回值说明
非 0返回 解析后的XML文档句柄。
0失败。

注意事项

项目说明
路径文件路径支持相对路径和绝对路径。
格式文件必须是有效的XML格式。
解析成功后需要调用 XmlFree 释放资源解析成功后需要调用 XmlFree 释放资源。
如果文件不存在或无法读取如果文件不存在或无法读取,返回0。